<template>
    <div class="userCenter">
        <div class="breadcrumb-box">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>个人中心</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="center container td-f">
            <left-nav-bar :active="active"></left-nav-bar>
            <div class="right">
                <div class="line-ti">
                    <div>账单明细</div>
                </div>
                <div style="height:50px"></div>
                <div class="block">
                    <el-date-picker v-model="date" value-format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                </div>
                <div style="height:50px"></div>
                <el-table :data="messageList" style="width: 100%" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column prop="order_name" label="订单名称" width="180">
                    </el-table-column>
                    <el-table-column prop="status_text" label="审核状态" width="180">
                    </el-table-column>
                    <el-table-column prop="amount" label="金额">
                    </el-table-column>
                    <el-table-column prop="create_time" label="生成时间">
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="100">
                        <template slot-scope="scope">
                            <el-button @click="navDetail(scope.row.pay_type,scope.row.order_id,scope.row.type)" type="text" size="small">查看详情</el-button>
                            <el-button @click="handleClick(scope.row)" type="text" size="small" v-if="scope.row == 2">查看原因</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div class="nodata" v-if="messageList.length == 0">
                    <img :src="$global.Image.noOrder" />
                </div>
                <div class="cart-bottom">
                <div class="container td-fbc">
                    <div class="td-fbc left" style="flex:1">
                        <label class="td-fbc btn-cp" @click="exportGood">
                            导出
                        </label>
                    </div>
                </div>
            </div>
                <div class="pagination-box">
                    <el-pagination background layout="prev, pager, next" @current-change="_handelClickPage" :total="total" :page-size="10"></el-pagination>
                </div>
            </div>
            
            <div v-show="showDialog">
                <div class="add-address-show">
                    <div class="title">
                        <div>清单导出</div>
                        <img :src="$global.Image.icon_close" @click="_cancelDialog" />
                    </div>
                    <div class="add-input">

                        <div class="email">
                            <div class="email-tit"><span>*</span>收件邮箱</div>
                            <el-input v-model="email" placeholder="请输入收件邮箱"></el-input>
                        </div>
                        <div class="choose-type">
                            <div class="cancel" @click="_cancelDialog">取消</div>
                            <div class="confirm" @click="_confirmDialog">确认</div>
                        </div>
                    </div>
                </div>
                <div class="dialog-shade"></div>
            </div>
        </div>
        <div style="height: 200px"></div>
    </div>
</template>

<script>
import { exportProduct } from "@api/user";
import leftNavBar from "@components/leftNavBar";
import { getUser, getMyMessage, searchQuota, cashLog } from "@api/user";

export default {
    name: "userCenter",
    data() {
        return {
            loading: false,
            active: 1,
            userInfo: {},
            messageList: [],
            quotaInfo: "",
            total:'',
            orderStatusNum: {},
            dialogImageUrl: "",
            dialogVisible: false,
            showDialog: false,
            selectGood: [],
            limit: 10,
            multipleSelection: [],
            start: "",
            date: "",
            end: "",
            selectId: [],
            email: "",
            page: 1,
        };
    },
    components: {
        leftNavBar,
    },
    watch: {
        date(e) {
            console.log(e);
            if (e == null) {
                this.start = "";
                this.end = "";
                this.getCashLog();
                return;
            }
            this.start = e[0];
            this.end = e[1];
            this.getCashLog();
        },
    },
    methods: {
        handleSelectionChange(val) {
            this.selectGood = val;
        },
        exportGood() {
            let selectGood = this.selectGood;
            let selectId = this.selectId;
            if (selectGood.length == 0) {
                return;
            }
            this.selectGood.map((item, index) => {
                selectId.push(item.id);
            });
            this.selectId = selectId;
            this.showDialog = true;
        },
        _cancelDialog() {
            this.showDialog = false;
        },
        _confirmDialog() {
            let that = this;
            if (!that.email) {
                that.$dialog.toast({ mes: "请输入收件邮箱" });
                return;
            }
            if (!that.selectId.length) {
                that.$dialog.toast({ mes: "请选择要导出的订单" });
                return;
            }
            let id = that.selectId;
            let params = {
                type: 2,
                id: id.join(","),
                email: that.email,
            };
            exportProduct(params)
                .then(function (res) {
                    if (res.status != 200) {
                        that.$dialog.toast({ mes: res.msg });
                        return;
                    }
                    that.$dialog.toast({ mes: "导出成功，请注意查收邮件。" });

                    that.showDialog = false;
                    setTimeout(() => {
                        that.getCashLog();
                    }, 1000);
                })
                .catch((err) => {
                    that.$dialog.error(err.msg);
                });
        },
        // 跳转详情，但需要先判断是不是有效订单
        navDetail(pay_type, order_id, type) {
            if (pay_type == "weixin" && type == 0) {
                this.$router.push({
                    path: "/orderDetails/" + order_id,
                });
            } else {
                this.$alert("该订单不是微信支付订单，不能查看", "提示", {
                    confirmButtonText: "确定",
                    callback: (action) => {},
                });
            }
        },
        handleClick(row) {
            console.log(row);
            if (row.status == 2) {
                this.$alert(`未通过原因:${row.deal_desc}`, "审核失败", {
                    confirmButtonText: "确定",
                    callback: (action) => {},
                });
                return;
            }
        },
        User() {
            let that = this;
            getUser().then((res) => {
                that.userInfo = res.data;

                that.orderStatusNum = res.data.orderStatusNum;
            });
        },
        // 获取记录列表
        getCashLog() {
            let data = {
                limit: this.limit,
                page: this.page,
                end: this.end,
                start: this.start,
            };
            cashLog(data)
                .then((res) => {
                    console.log(res);
                    this.total = res.data.count;
                    this.messageList = res.data.list;
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        // 切换页面
        _handelClickPage(e) {
            console.log(e);
            this.page = e;
            this.getCashLog();
        },
    },
    mounted() {
        this.User();
        this.getCashLog();
    },
};
</script>
<style >
.el-upload--picture-card {
    width: 88px;
    height: 88px;
    line-height: 88px;
}
.el-upload-list--picture-card .el-upload-list__item {
    width: 88px;
    height: 88px;
}
</style>
<style scoped  rel="stylesheet/scss" lang="scss" scoped>
$color: #da213d;
.userCenter {
    width: 100%;
    height: 100%;

    .center {
        /*width: 70%;*/
        margin: 0 auto;
        display: flex;

        .right {
            width: 1000px;
            margin-left: 32px;
            /*margin-top: 90px;*/
            .list {
                .itm {
                    float: left;
                    margin-top: 20px;
                    width: 405px;
                    margin-right: 20px;
                    padding: 12px 17px;
                    border: 1px solid #eaa090;
                    border-radius: 5px;
                    .itm-top {
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        div {
                            &:nth-child(1) {
                                font-size: 16px;
                                color: #333333;
                                letter-spacing: 1px;
                            }
                            &:nth-child(2) {
                                font-size: 15px;
                                font-weight: bold;
                                color: #da213d;
                            }
                            &:nth-child(2).success {
                                color: #45b39c;
                            }
                        }
                    }
                    .itm-cen {
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        margin-top: 5px;
                        div {
                            &:nth-child(1) {
                                font-size: 16px;
                                font-weight: bold;
                                color: #333333;
                            }
                            &:nth-child(2) {
                                font-size: 14px;
                                color: #999999;
                            }
                        }
                    }
                    .itm-botm {
                        padding-top: 9px;
                        margin-top: 15px;
                        border-top: 1px dashed #eee8e8;
                        font-size: 13px;
                        color: #666666;
                        letter-spacing: 1px;
                    }
                    &:nth-child(2n) {
                        margin-right: 0;
                    }
                }
            }
            .ti-top {
                border: 1px solid #efc2c1;
                border-top-left-radius: 5px;
                border-top-right-radius: 5px;
                .right-top {
                    display: flex;
                    height: 160px;
                    align-items: center;
                    background: url("../../assets/second_icon/center_bg.png")
                        no-repeat;
                    background-size: 100% 100%;
                    position: relative;

                    .left-ava {
                        margin-left: 55px;
                        width: 82px;
                        height: 82px;
                        border-radius: 50%;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        background-color: #fff;
                        box-shadow: inset 0 0 5px 1px
                            rgba($color: #000000, $alpha: 0.2);
                        img {
                            width: 74px;
                            height: 74px;
                            border-radius: 50%;
                        }
                    }
                    .detaiult-avatar {
                        margin-left: 55px;
                        width: 99px;
                        height: 99px;
                        border-radius: 50%;
                        background-color: #fff;
                        box-shadow: inset 0 0 5px 1px
                            rgba($color: #000000, $alpha: 0.2);
                        img {
                            width: 66px;
                            height: 66px;
                            margin-left: 10px;
                        }
                    }

                    .right-txt {
                        display: flex;
                        height: 99px;
                        justify-content: center;
                        align-items: center;
                        margin-left: 5px;

                        > div:nth-of-type(1) {
                            color: #ffffff;
                            font-size: 20px;
                            margin-left: 20px;
                            text-align: justify;
                        }

                        > div:nth-of-type(2) {
                            height: 32px;
                            line-height: 32px;
                            padding: 0 20px;
                            text-align: center;
                            margin-left: 20px;
                            background: linear-gradient(
                                270deg,
                                rgba(23, 22, 20, 0.3) 1%,
                                rgba(99, 77, 77, 0.3)
                            );
                            border-radius: 15px;
                            color: rgba(255, 255, 255, 1);
                            font-size: 18px;
                            // margin-top: 19px;
                            small {
                                padding-right: 2px;
                            }
                        }
                    }

                    .set-btn {
                        position: absolute;
                        right: 30px;
                        top: 50%;
                        width: 70px;
                        height: 30px;
                        font-size: 16px;
                        color: #fff;
                        cursor: pointer;
                        border-radius: 8px;
                        border: 1px solid #da213d;
                        background: #da213d;
                        transform: translateY(-50%);
                        transition: all 0.3s;
                    }

                    .set-btn:hover {
                        background: #fff;
                        color: #da213d;
                    }
                }

                .right-list {
                    display: flex;
                    height: 130px;
                    width: 100%;
                    align-items: center;
                    justify-content: space-around;
                    // margin: 0 auto;
                    cursor: pointer;

                    .li {
                        display: flex;
                        flex-direction: column;
                        width: 33.3%;
                        justify-content: center;
                        align-items: center;
                        position: relative;
                        &::before {
                            position: absolute;
                            right: 0;
                            top: 0;
                            bottom: 0;
                            margin: auto 0;
                            content: "";
                            width: 2px;
                            height: 47px;
                            background: #ecdfdd;
                            border-radius: 1px;
                        }
                        > div:nth-of-type(1) {
                            min-width: 25px;
                            height: 25px;
                            line-height: 25px;
                            text-align: center;
                            background-color: $color;
                            color: #ffffff;
                            font-size: 15px;
                            position: absolute;
                            z-index: 2;
                            border-radius: 50%;
                            margin: -40px 0 0 30px;
                        }

                        img {
                            width: 50px;
                            height: 41px;
                            object-fit: contain;
                        }

                        div:nth-of-type(2) {
                            color: rgba(102, 102, 102, 1);
                            font-size: 17px;
                            font-family: MicrosoftYaHei;
                            margin-top: 13px;
                        }
                    }

                    .li:last-child {
                        img {
                            max-width: 54px;
                        }
                        &::before {
                            display: none;
                        }
                    }
                }
            }

            .line-ti {
                width: 100%;
                border-bottom: 3px solid #dbdbdb;
                height: 40px;
                > div {
                    color: #da213d;
                    font-size: 18px;
                    font-family: MicrosoftYaHei-Bold;
                    border-bottom: 3px solid $color;
                    width: 72px;
                    height: 40px;
                    font-weight: bold;
                    line-height: 36px;
                    padding-left: 5px;
                }
            }

            .shop-list {
                .shop-li {
                    padding-bottom: 10px;

                    .top {
                        display: flex;
                        align-content: center;
                        justify-content: space-between;
                        margin: 30px 0 16px 0;

                        .le {
                            display: flex;
                            height: 24px;
                            align-items: center;

                            img {
                                width: 18px;
                                height: 16px;
                            }

                            > div {
                                color: rgba(51, 51, 51, 1);
                                font-size: 17px;
                                font-family: MicrosoftYaHei;
                                padding-left: 12px;
                            }
                        }

                        .ri {
                            > div {
                                color: #999999;
                            }
                        }
                    }

                    .bot {
                        width: 100%;
                        height: 40px;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;

                        .l {
                            display: flex;
                            height: 80px;
                            align-items: center;
                            margin-left: 15px;

                            img {
                                width: 80px;
                                height: 80px;
                            }

                            > div {
                                color: #333333;
                                padding-left: 15px;
                                font-size: 16px;
                                font-weight: 500;
                                width: 500px;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                            }
                        }

                        .r {
                            width: 85px;
                            height: 30px;
                            line-height: 30px;
                            text-align: center;
                            background: $color;
                            color: #3d75af;
                            font-size: 14px;
                            margin-right: 15px;
                            border-radius: 2px;
                            cursor: pointer;
                        }
                    }
                }

                .shop-li:not(:last-child) {
                    border-bottom: 1px solid #dbdbdb;
                }
            }
        }
    }
}
.cart-bottom {
    background-color: #fff;
    left: 0;
    width: 100%;
    .container {
        height: 80px;
    }
    .icon-checked {
        height: 20px;
        width: 20px;
        object-fit: contain;
        margin-right: 10px;
    }
    .left {
        .btn-cp {
            cursor: pointer;
            width: 108px;
            display: block;
            font-size: 13px;
            text-align: center;
            color: #ffffff;
            line-height: 34px;
            height: 34px;
            background: linear-gradient(143deg, #da213d 23%, #da213d 90%);
            border-radius: 5px;
            margin-right: auto;
        }

        .btn-cp:hover {
            // color: #da213d;
            span {
                color: #da213d;
            }
        }
        span {
            font-size: 16px;
            color: #333;
        }
        .choose-good {
            display: flex;
            justify-content: flex-end;
            align-items: center;
            flex: 1;
            margin-right: 68px;
        }
        .span-btn {
            color: #666;
            padding-left: 40px;
            b {
                font-size: 18px;
                padding: 0 4px;
            }
        }
    }
    .total-box {
        font-size: 16px;
        color: #333;
        margin-right: 70px;
        height: 60px;
        span {
            font-size: 24px;
            font-weight: 600;
            color: #da213d;
        }
        .discount {
            font-size: 14px;
            color: #999;
        }
    }
    .btn-r {
        height: 80px;
        width: 200px;
        font-size: 21px;
        font-weight: 700;
        letter-spacing: 2px;
        color: #ffffff !important;
    }
}
.add-address-show {
    position: fixed;
    left: 0;
    right: 0;
    top: 50%;
    bottom: 50%;
    width: 700px;
    min-height: 250px;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 1);
    box-shadow: 0 0 15px 4px rgba(0, 0, 0, 0.2);
    margin: auto;
    z-index: 101;
    .title {
        display: flex;
        width: 100%;
        height: 67px;
        align-items: center;
        background: #fbf0f0;
        justify-content: center;
        > div:nth-of-type(1) {
            font-size: 21px;
            font-weight: bold;
            color: #da213d;
        }
        img {
            display: block;
            width: 20px;
            height: 20px;
            font-size: 30px;
            color: #999999;
            position: absolute;
            right: 32px;
            cursor: pointer;
        }
    }
    .add-input {
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;
        padding: 20px 0 40px;
        .scroll {
            height: 310px;
            width: 100%;
            overflow-y: scroll;
            &::-webkit-scrollbar {
                width: 0;
                height: 0;
                display: none;
            }
            .goods-itm {
                margin: 0 auto;
                width: 550px;
                height: 150px;
                border: 1px solid #eaa090;
                margin-bottom: 10px;
                display: flex;
                align-items: center;
                padding: 0 20px;
                box-sizing: border-box;
                .goods-img {
                    width: 126px;
                    height: 126px;
                }
                .goods-right {
                    margin-left: 20px;
                    .goods-tit {
                        font-size: 20px;
                        font-weight: bold;
                        text-align: justify;
                        color: #333333;
                        line-height: 26px;
                        text-overflow: -o-ellipsis-lastline;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        display: -webkit-box;
                        -webkit-line-clamp: 2;
                        -webkit-box-orient: vertical;
                    }
                    .goods-choies {
                        font-size: 14px;
                        color: #999999;
                        margin-top: 14px;
                        .span1 {
                        }
                        .span2 {
                            margin-left: 60px;
                        }
                    }
                    .goods-price {
                        margin-top: 10px;
                        font-size: 20px;
                        font-weight: bold;
                        color: #da213d;
                    }
                }
            }
        }
    }
    .rule-form {
        width: 460px;
        button {
            width: 140px;
        }
    }
}
.email {
    display: flex;
    margin-top: 20px;
    .email-tit {
        font-size: 15px;
        width: 100px;
        line-height: 40px;
        span {
            color: #da213d;
            font-size: 15px;
        }
    }
    .el-input {
        width: 400px;
    }
}
.dialog-shade {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 18;
    background-color: rgba($color: #000000, $alpha: 0.4);
}
.choose-type {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    width: 100%;
    padding: 0 70px;
    box-sizing: border-box;
    .cancel {
        width: 242px;
        height: 46px;
        border: 1px solid #da213d;
        border-radius: 5px;
        font-size: 16px;
        text-align: center;
        color: #da213d;
        line-height: 46px;
        cursor: pointer;
    }
    .confirm {
        width: 240px;
        height: 44px;
        background: #da213d;
        border-radius: 5px;
        font-size: 16px;
        text-align: center;
        color: #ffffff;
        line-height: 44px;
        cursor: pointer;
    }
}
</style>
